home *** CD-ROM | disk | FTP | other *** search
/ Delphi Magazine Collection 2001 / Delphi Magazine Collection 20001 (2001).iso / DISKS / Issue57 / Clinic / ActiveFormImpl.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  2000-03-24  |  9.0 KB  |  359 lines

  1. unit ActiveFormImpl;
  2.  
  3. interface
  4.  
  5. uses
  6.   Windows, Messages, SysUtils, Classes, Graphics, Controls, Forms, Dialogs,
  7.   ActiveX, AxCtrls, ActiveX_TLB, StdVcl, StdCtrls;
  8.  
  9. type
  10.   TActiveFormX = class(TActiveForm, IActiveFormX)
  11.     Label1: TLabel;
  12.   private
  13.     { Private declarations }
  14.     FEvents: IActiveFormXEvents;
  15.     procedure ActivateEvent(Sender: TObject);
  16.     procedure ClickEvent(Sender: TObject);
  17.     procedure CreateEvent(Sender: TObject);
  18.     procedure DblClickEvent(Sender: TObject);
  19.     procedure DeactivateEvent(Sender: TObject);
  20.     procedure DestroyEvent(Sender: TObject);
  21.     procedure KeyPressEvent(Sender: TObject; var Key: Char);
  22.     procedure PaintEvent(Sender: TObject);
  23.     { My new methods }
  24.     //Published property reader
  25.     function GetMyNewFormProp: String;
  26.     //Published property writer
  27.     procedure SetMyNewFormProp(const Value: String);
  28.   protected
  29.     { Protected declarations }
  30.     procedure DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage); override;
  31.     procedure EventSinkChanged(const EventSink: IUnknown); override;
  32.     function Get_Active: WordBool; safecall;
  33.     function Get_AutoScroll: WordBool; safecall;
  34.     function Get_AutoSize: WordBool; safecall;
  35.     function Get_AxBorderStyle: TxActiveFormBorderStyle; safecall;
  36.     function Get_Caption: WideString; safecall;
  37.     function Get_Color: OLE_COLOR; safecall;
  38.     function Get_Cursor: Smallint; safecall;
  39.     function Get_DoubleBuffered: WordBool; safecall;
  40.     function Get_DropTarget: WordBool; safecall;
  41.     function Get_Enabled: WordBool; safecall;
  42.     function Get_Font: IFontDisp; safecall;
  43.     function Get_HelpFile: WideString; safecall;
  44.     function Get_KeyPreview: WordBool; safecall;
  45.     function Get_PixelsPerInch: Integer; safecall;
  46.     function Get_PrintScale: TxPrintScale; safecall;
  47.     function Get_Scaled: WordBool; safecall;
  48.     function Get_Visible: WordBool; safecall;
  49.     function Get_VisibleDockClientCount: Integer; safecall;
  50.     procedure _Set_Font(const Value: IFontDisp); safecall;
  51.     procedure Set_AutoScroll(Value: WordBool); safecall;
  52.     procedure Set_AutoSize(Value: WordBool); safecall;
  53.     procedure Set_AxBorderStyle(Value: TxActiveFormBorderStyle); safecall;
  54.     procedure Set_Caption(const Value: WideString); safecall;
  55.     procedure Set_Color(Value: OLE_COLOR); safecall;
  56.     procedure Set_Cursor(Value: Smallint); safecall;
  57.     procedure Set_DoubleBuffered(Value: WordBool); safecall;
  58.     procedure Set_DropTarget(Value: WordBool); safecall;
  59.     procedure Set_Enabled(Value: WordBool); safecall;
  60.     procedure Set_Font(var Value: IFontDisp); safecall;
  61.     procedure Set_HelpFile(const Value: WideString); safecall;
  62.     procedure Set_KeyPreview(Value: WordBool); safecall;
  63.     procedure Set_PixelsPerInch(Value: Integer); safecall;
  64.     procedure Set_PrintScale(Value: TxPrintScale); safecall;
  65.     procedure Set_Scaled(Value: WordBool); safecall;
  66.     procedure Set_Visible(Value: WordBool); safecall;
  67.     function Get_MyNewFormProp: WideString; safecall;
  68.     procedure Set_MyNewFormProp(const Value: WideString); safecall;
  69.   public
  70.     { Public declarations }
  71.     procedure Initialize; override;
  72.   published
  73.     property MyNewFormProp: String read GetMyNewFormProp write SetMyNewFormProp;
  74.   end;
  75.  
  76. implementation
  77.  
  78. uses ComObj, ComServ;
  79.  
  80. {$R *.DFM}
  81.  
  82. { TActiveFormX }
  83.  
  84. procedure TActiveFormX.DefinePropertyPages(DefinePropertyPage: TDefinePropertyPage);
  85. begin
  86.   { Define property pages here.  Property pages are defined by calling
  87.     DefinePropertyPage with the class id of the page.  For example,
  88.       DefinePropertyPage(Class_ActiveFormXPage); }
  89. end;
  90.  
  91. procedure TActiveFormX.EventSinkChanged(const EventSink: IUnknown);
  92. begin
  93.   FEvents := EventSink as IActiveFormXEvents;
  94. end;
  95.  
  96. procedure TActiveFormX.Initialize;
  97. begin
  98.   inherited Initialize;
  99.   OnActivate := ActivateEvent;
  100.   OnClick := ClickEvent;
  101.   OnCreate := CreateEvent;
  102.   OnDblClick := DblClickEvent;
  103.   OnDeactivate := DeactivateEvent;
  104.   OnDestroy := DestroyEvent;
  105.   OnKeyPress := KeyPressEvent;
  106.   OnPaint := PaintEvent;
  107. end;
  108.  
  109. function TActiveFormX.Get_Active: WordBool;
  110. begin
  111.   Result := Active;
  112. end;
  113.  
  114. function TActiveFormX.Get_AutoScroll: WordBool;
  115. begin
  116.   Result := AutoScroll;
  117. end;
  118.  
  119. function TActiveFormX.Get_AutoSize: WordBool;
  120. begin
  121.   Result := AutoSize;
  122. end;
  123.  
  124. function TActiveFormX.Get_AxBorderStyle: TxActiveFormBorderStyle;
  125. begin
  126.   Result := Ord(AxBorderStyle);
  127. end;
  128.  
  129. function TActiveFormX.Get_Caption: WideString;
  130. begin
  131.   Result := WideString(Caption);
  132. end;
  133.  
  134. function TActiveFormX.Get_Color: OLE_COLOR;
  135. begin
  136.   Result := OLE_COLOR(Color);
  137. end;
  138.  
  139. function TActiveFormX.Get_Cursor: Smallint;
  140. begin
  141.   Result := Smallint(Cursor);
  142. end;
  143.  
  144. function TActiveFormX.Get_DoubleBuffered: WordBool;
  145. begin
  146.   Result := DoubleBuffered;
  147. end;
  148.  
  149. function TActiveFormX.Get_DropTarget: WordBool;
  150. begin
  151.   Result := DropTarget;
  152. end;
  153.  
  154. function TActiveFormX.Get_Enabled: WordBool;
  155. begin
  156.   Result := Enabled;
  157. end;
  158.  
  159. function TActiveFormX.Get_Font: IFontDisp;
  160. begin
  161.   GetOleFont(Font, Result);
  162. end;
  163.  
  164. function TActiveFormX.Get_HelpFile: WideString;
  165. begin
  166.   Result := WideString(HelpFile);
  167. end;
  168.  
  169. function TActiveFormX.Get_KeyPreview: WordBool;
  170. begin
  171.   Result := KeyPreview;
  172. end;
  173.  
  174. function TActiveFormX.Get_PixelsPerInch: Integer;
  175. begin
  176.   Result := PixelsPerInch;
  177. end;
  178.  
  179. function TActiveFormX.Get_PrintScale: TxPrintScale;
  180. begin
  181.   Result := Ord(PrintScale);
  182. end;
  183.  
  184. function TActiveFormX.Get_Scaled: WordBool;
  185. begin
  186.   Result := Scaled;
  187. end;
  188.  
  189. function TActiveFormX.Get_Visible: WordBool;
  190. begin
  191.   Result := Visible;
  192. end;
  193.  
  194. function TActiveFormX.Get_VisibleDockClientCount: Integer;
  195. begin
  196.   Result := VisibleDockClientCount;
  197. end;
  198.  
  199. procedure TActiveFormX._Set_Font(const Value: IFontDisp);
  200. begin
  201.   SetOleFont(Font, Value);
  202. end;
  203.  
  204. procedure TActiveFormX.ActivateEvent(Sender: TObject);
  205. begin
  206.   if FEvents <> nil then FEvents.OnActivate;
  207. end;
  208.  
  209. procedure TActiveFormX.ClickEvent(Sender: TObject);
  210. begin
  211.   if FEvents <> nil then FEvents.OnClick;
  212. end;
  213.  
  214. procedure TActiveFormX.CreateEvent(Sender: TObject);
  215. begin
  216.   if FEvents <> nil then FEvents.OnCreate;
  217. end;
  218.  
  219. procedure TActiveFormX.DblClickEvent(Sender: TObject);
  220. begin
  221.   if FEvents <> nil then FEvents.OnDblClick;
  222. end;
  223.  
  224. procedure TActiveFormX.DeactivateEvent(Sender: TObject);
  225. begin
  226.   if FEvents <> nil then FEvents.OnDeactivate;
  227. end;
  228.  
  229. procedure TActiveFormX.DestroyEvent(Sender: TObject);
  230. begin
  231.   if FEvents <> nil then FEvents.OnDestroy;
  232. end;
  233.  
  234. procedure TActiveFormX.KeyPressEvent(Sender: TObject; var Key: Char);
  235. var
  236.   TempKey: Smallint;
  237. begin
  238.   TempKey := Smallint(Key);
  239.   if FEvents <> nil then FEvents.OnKeyPress(TempKey);
  240.   Key := Char(TempKey);
  241. end;
  242.  
  243. procedure TActiveFormX.PaintEvent(Sender: TObject);
  244. begin
  245.   if FEvents <> nil then FEvents.OnPaint;
  246. end;
  247.  
  248. procedure TActiveFormX.Set_AutoScroll(Value: WordBool);
  249. begin
  250.   AutoScroll := Value;
  251. end;
  252.  
  253. procedure TActiveFormX.Set_AutoSize(Value: WordBool);
  254. begin
  255.   AutoSize := Value;
  256. end;
  257.  
  258. procedure TActiveFormX.Set_AxBorderStyle(Value: TxActiveFormBorderStyle);
  259. begin
  260.   AxBorderStyle := TActiveFormBorderStyle(Value);
  261. end;
  262.  
  263. procedure TActiveFormX.Set_Caption(const Value: WideString);
  264. begin
  265.   Caption := TCaption(Value);
  266. end;
  267.  
  268. procedure TActiveFormX.Set_Color(Value: OLE_COLOR);
  269. begin
  270.   Color := TColor(Value);
  271. end;
  272.  
  273. procedure TActiveFormX.Set_Cursor(Value: Smallint);
  274. begin
  275.   Cursor := TCursor(Value);
  276. end;
  277.  
  278. procedure TActiveFormX.Set_DoubleBuffered(Value: WordBool);
  279. begin
  280.   DoubleBuffered := Value;
  281. end;
  282.  
  283. procedure TActiveFormX.Set_DropTarget(Value: WordBool);
  284. begin
  285.   DropTarget := Value;
  286. end;
  287.  
  288. procedure TActiveFormX.Set_Enabled(Value: WordBool);
  289. begin
  290.   Enabled := Value;
  291. end;
  292.  
  293. procedure TActiveFormX.Set_Font(var Value: IFontDisp);
  294. begin
  295.   SetOleFont(Font, Value);
  296. end;
  297.  
  298. procedure TActiveFormX.Set_HelpFile(const Value: WideString);
  299. begin
  300.   HelpFile := String(Value);
  301. end;
  302.  
  303. procedure TActiveFormX.Set_KeyPreview(Value: WordBool);
  304. begin
  305.   KeyPreview := Value;
  306. end;
  307.  
  308. procedure TActiveFormX.Set_PixelsPerInch(Value: Integer);
  309. begin
  310.   PixelsPerInch := Value;
  311. end;
  312.  
  313. procedure TActiveFormX.Set_PrintScale(Value: TxPrintScale);
  314. begin
  315.   PrintScale := TPrintScale(Value);
  316. end;
  317.  
  318. procedure TActiveFormX.Set_Scaled(Value: WordBool);
  319. begin
  320.   Scaled := Value;
  321. end;
  322.  
  323. procedure TActiveFormX.Set_Visible(Value: WordBool);
  324. begin
  325.   Visible := Value;
  326. end;
  327.  
  328. function TActiveFormX.GetMyNewFormProp: String;
  329. begin
  330.   Result := Label1.Caption
  331. end;
  332.  
  333. procedure TActiveFormX.SetMyNewFormProp(const Value: String);
  334. begin
  335.   Label1.Caption := Value
  336. end;
  337.  
  338. function TActiveFormX.Get_MyNewFormProp: WideString;
  339. begin
  340.   Result := MyNewFormProp
  341. end;
  342.  
  343. procedure TActiveFormX.Set_MyNewFormProp(const Value: WideString);
  344. begin
  345.   MyNewFormProp := Value
  346. end;
  347.  
  348. initialization
  349.   TActiveFormFactory.Create(
  350.     ComServer,
  351.     TActiveFormControl,
  352.     TActiveFormX,
  353.     Class_ActiveFormX,
  354.     1,
  355.     '',
  356.     OLEMISC_SIMPLEFRAME or OLEMISC_ACTSLIKELABEL,
  357.     tmApartment);
  358. end.
  359.